

export const getCategoryTree = (data: Category[], pid: number = 0): Category[]=>{
    const tree: Category[] = [];
    for (const item of data) {
        if (item.pid === pid) {
            const children = getCategoryTree(data, item.id);
            if (children.length > 0) {
                item.children = children;
            }
            tree.push({ ...item }); // 可选：避免直接修改原始对象
        }
    }
    return tree;
}